 package com.coc.util;
 
 import com.Ostermiller.util.Base64;
 import com.coc.bean.CocServer;
 import com.coc.bean.CocServer2;
 import com.coc.bean.CocSetting;
 import com.coc.bean.FileVersion;
 import com.coc.dao.EloUserDAO;
 import java.io.IOException;
 import java.io.PrintStream;
 import java.net.URLEncoder;
 import java.security.MessageDigest;
 import java.text.SimpleDateFormat;
 import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import javax.crypto.Mac;
 import javax.crypto.SecretKey;
 import javax.crypto.spec.SecretKeySpec;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.springframework.context.ApplicationContext;
 import org.springframework.web.context.support.WebApplicationContextUtils;
 import sun.misc.BASE64Decoder;
 
 public class PubFun
 {
   private static int v = 0;
 
   public static void test2(List list) { list.add("123test"); }
 
   public static String test(String test) {
     System.out.println(test);
     return test + " 123";
   }
 
   public static String getV3LikeResult(HttpServletRequest request, String openid, String openkey, String pf) {
     try {
       String urlbase = "/v3/page/is_fans";
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       CocSetting ss = sud.findcs();
       String APP_ID = ss.getAppid();
       String APP_KEY = ss.getAppkey();
       String v3proxy = ss.getV3proxy();
       String v3ip = ss.getV3ip();
       if ((v3proxy != null) && (v3proxy.length() > 0)) {
         v3ip = getManagerHost(request, 1).split(":")[0] + ":" + 
           getNginxHost(request, 1).split(":")[1] + "/" + 
           v3proxy;
       }
       String URL_REST_SERVER_v3 = "http://" + v3ip;
       String secretstr = APP_KEY + "&";
       String Algorithm = "HmacSHA1";
       SecretKey secretKey = new SecretKeySpec(secretstr.getBytes(), 
         Algorithm);
       urlbase = URLEncoder.encode(urlbase, "utf-8");
       urlbase = "GET&" + urlbase;
       String postdata_v3 = "openid=" + 
         openid + 
         "&openkey=" + 
         openkey + 
         "&appid=" + 
         APP_ID + 
         "&pf=" + 
         pf + 
         "&page_id=" + 
         ss.getLikeurl().substring(
         ss.getLikeurl().lastIndexOf("/") + 1);
       String md5Str = sortPostData(postdata_v3);
       md5Str = URLEncoder.encode(md5Str, "utf-8");
       urlbase = urlbase + "&" + md5Str;
       Mac mac = Mac.getInstance(Algorithm);
       mac.init(secretKey);
       byte[] result = mac.doFinal(urlbase.getBytes());
       String sig = Base64.encodeToString(result);
       sig = URLEncoder.encode(sig, "utf-8");
       return doHttpClientGet(URL_REST_SERVER_v3 + 
         "/v3/page/is_fans?" + postdata_v3 + "&sig=" + sig);
     }
     catch (Exception e) {
       e.printStackTrace();
     }return "";
   }
 
   public static String getV3UserResult(HttpServletRequest request, String openid, String openkey, String pf)
   {
     try
     {
       String urlbase = "/v3/user/get_info";
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       CocSetting ss = sud.findcs();
       String APP_ID = ss.getAppid();
       String APP_KEY = ss.getAppkey();
       String v3proxy = ss.getV3proxy();
       String v3ip = ss.getV3ip();
       if ((v3proxy != null) && (v3proxy.length() > 0)) {
         v3ip = getManagerHost(request, 1).split(":")[0] + ":" + 
           getNginxHost(request, 1).split(":")[1] + "/" + 
           v3proxy;
       }
       String URL_REST_SERVER_v3 = "http://" + v3ip;
       String secretstr = APP_KEY + "&";
       String Algorithm = "HmacSHA1";
       SecretKey secretKey = new SecretKeySpec(secretstr.getBytes(), 
         Algorithm);
       urlbase = URLEncoder.encode(urlbase, "utf-8");
       urlbase = "GET&" + urlbase;
       String postdata_v3 = "openid=" + openid + "&openkey=" + openkey + 
         "&appid=" + APP_ID + "&pf=" + pf;
       String md5Str = sortPostData(postdata_v3);
       md5Str = URLEncoder.encode(md5Str, "utf-8");
       urlbase = urlbase + "&" + md5Str;
       Mac mac = Mac.getInstance(Algorithm);
       mac.init(secretKey);
       byte[] result = mac.doFinal(urlbase.getBytes());
       String sig = Base64.encodeToString(result);
       sig = URLEncoder.encode(sig, "utf-8");
       return doHttpClientGet(URL_REST_SERVER_v3 + 
         "/v3/user/get_info?" + postdata_v3 + "&sig=" + sig);
     }
     catch (Exception e) {
       e.printStackTrace();
     }return "";
   }
 
   public static String getV3DelMsgResult(HttpServletRequest request, String openid, String openkey, String pf)
   {
     try
     {
       String urlbase = "/v3/spread/del_appassist_msg";
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       CocSetting ss = sud.findcs();
       String APP_ID = ss.getAppid();
       String APP_KEY = ss.getAppkey();
       String v3proxy = ss.getV3proxy();
       String v3ip = ss.getV3ip();
       if ((v3proxy != null) && (v3proxy.length() > 0)) {
         v3ip = getManagerHost(request, 1).split(":")[0] + ":" + 
           getNginxHost(request, 1).split(":")[1] + "/" + 
           v3proxy;
       }
       String URL_REST_SERVER_v3 = "http://" + v3ip;
       String secretstr = APP_KEY + "&";
       String Algorithm = "HmacSHA1";
       SecretKey secretKey = new SecretKeySpec(secretstr.getBytes(), 
         Algorithm);
       urlbase = URLEncoder.encode(urlbase, "utf-8");
       urlbase = "GET&" + urlbase;
       String postdata_v3 = "openid=" + openid + "&openkey=" + openkey + 
         "&appid=" + APP_ID + "&pf=" + pf;
       String md5Str = sortPostData(postdata_v3);
       md5Str = URLEncoder.encode(md5Str, "utf-8");
       urlbase = urlbase + "&" + md5Str;
       Mac mac = Mac.getInstance(Algorithm);
       mac.init(secretKey);
       byte[] result = mac.doFinal(urlbase.getBytes());
       String sig = Base64.encodeToString(result);
       sig = URLEncoder.encode(sig, "utf-8");
       return doHttpClientGet(URL_REST_SERVER_v3 + 
         "/v3/spread/del_appassist_msg?" + postdata_v3 + "&sig=" + 
         sig);
     }
     catch (Exception e) {
       e.printStackTrace();
     }return "";
   }
 
   public static String getV3BalanceResult(HttpServletRequest request, String openid, String openkey, String pf, String pfkey)
   {
     try
     {
       String urlbase = "/v3/pay/get_balance";
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       CocSetting ss = sud.findcs();
       String APP_ID = ss.getAppid();
       String APP_KEY = ss.getAppkey();
       String v3proxy = ss.getV3proxy();
       String v3ip = ss.getV3ip();
       if ((v3proxy != null) && (v3proxy.length() > 0)) {
         v3ip = getManagerHost(request, 1).split(":")[0] + ":" + 
           getNginxHost(request, 1).split(":")[1] + "/" + 
           v3proxy;
       }
       String URL_REST_SERVER_v3 = "http://" + v3ip;
       String secretstr = APP_KEY + "&";
       String Algorithm = "HmacSHA1";
       SecretKey secretKey = new SecretKeySpec(secretstr.getBytes(), 
         Algorithm);
       urlbase = URLEncoder.encode(urlbase, "utf-8");
       urlbase = "GET&" + urlbase;
       String postdata_v3 = "openid=" + openid + "&openkey=" + openkey + 
         "&appid=" + APP_ID + "&pf=" + pf + "&pfkey=" + pfkey + 
         "&ts=" + System.currentTimeMillis() / 1000L + "&zoneid=0";
       String md5Str = sortPostData(postdata_v3);
       md5Str = URLEncoder.encode(md5Str, "utf-8");
       urlbase = urlbase + "&" + md5Str;
       Mac mac = Mac.getInstance(Algorithm);
       mac.init(secretKey);
       byte[] result = mac.doFinal(urlbase.getBytes());
       String sig = Base64.encodeToString(result);
       sig = URLEncoder.encode(sig, "utf-8");
       return doHttpClientGet(URL_REST_SERVER_v3 + 
         "/v3/pay/get_balance?" + postdata_v3 + "&sig=" + sig);
     }
     catch (Exception e) {
       e.printStackTrace();
     }return "";
   }
 
   public static String getV3BuyGoodResult(HttpServletRequest request, String openid, String openkey, String pf, String pfkey, String goodsmeta, String payitem, String img)
   {
     try
     {
       String urlbase = "/v3/pay/buy_goods";
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       CocSetting ss = sud.findcs();
       String APP_ID = ss.getAppid();
       String APP_KEY = ss.getAppkey();
       String v3proxy = ss.getV3proxy();
       String v3ip = ss.getV3ip();
       if ((v3proxy != null) && (v3proxy.length() > 0)) {
         v3ip = getManagerHost(request, 1).split(":")[0] + ":" + 
           getNginxHost(request, 1).split(":")[1] + "/" + 
           v3proxy;
       }
       String URL_REST_SERVER_v3 = "http://" + v3ip;
       String secretstr = APP_KEY + "&";
       String Algorithm = "HmacSHA1";
       SecretKey secretKey = new SecretKeySpec(secretstr.getBytes(), 
         Algorithm);
       urlbase = URLEncoder.encode(urlbase, "utf-8");
       urlbase = "GET&" + urlbase;
       String postdata_v3 = "openid=" + openid + "&openkey=" + openkey + 
         "&appid=" + APP_ID + "&pf=" + pf + "&pfkey=" + pfkey + 
         "&ts=" + System.currentTimeMillis() / 1000L + "&zoneid=0&amttype=coin&appmode=1&goodsmeta=" + goodsmeta + "&payitem=" + payitem + "&goodsurl=" + ss.getCdnroot() + img;
       String md5Str = sortPostData(postdata_v3);
       md5Str = URLEncoder.encode(md5Str, "utf-8");
       urlbase = urlbase + "&" + md5Str;
       Mac mac = Mac.getInstance(Algorithm);
       mac.init(secretKey);
       byte[] result = mac.doFinal(urlbase.getBytes());
       String sig = Base64.encodeToString(result);
       sig = URLEncoder.encode(sig, "utf-8");
       return doHttpClientGet(URL_REST_SERVER_v3 + 
         "/v3/pay/buy_goods?" + postdata_v3 + "&sig=" + sig);
     }
     catch (Exception e) {
       e.printStackTrace();
     }return "";
   }
 
   public static int getV(HttpServletRequest request)
   {
     if (v == 0) {
       try {
         ApplicationContext ctx = 
           WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
           .getServletContext());
         EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
         CocSetting ss = sud.findcs();
         v = Integer.parseInt(ss.getV());
       } catch (Exception e) {
         e.printStackTrace();
         v = -1;
       }
     }
     return v;
   }
 
   public static String getNginxHost(HttpServletRequest request, int id, int status)
   {
     try {
       if (id == 1) {
         return getNginxHost(request, status);
       }
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       List li = sud.findSVByTypes2(1, status);
       if (li.size() != 0) {
         CocServer2 sv = (CocServer2)li.get(0);
         return sv.getIp() + ":" + sv.getPort();
       }
       return "";
     } catch (Exception e) {
       e.printStackTrace();
     }return "";
   }
 
   public static boolean setNginxHosts(HttpServletRequest request, int id, String serverStr)
   {
     try
     {
       if (id == 1) {
         return setNginxHosts(request, serverStr);
       }
 
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
 
       List li = sud.findSVByTypes2(1, 1);
       for (int i = 0; i < li.size(); i++) {
         CocServer2 sv = (CocServer2)li.get(i);
         sud.delSV2(sv);
       }
       li = sud.findSVByTypes2(1, 0);
       for (int i = 0; i < li.size(); i++) {
         CocServer2 sv = (CocServer2)li.get(i);
         sud.delSV2(sv);
       }
       String[] str = serverStr.split(",");
       for (int i = 0; i < str.length; i++)
       {
         String[] tmp = str[i].split("\\|");
         CocServer2 sv = new CocServer2();
         sv.setTypes(Integer.valueOf(1));
         sv.setIp(str[i].substring(0, tmp[0].indexOf(":")));
         sv.setPort(str[i].substring(tmp[0].indexOf(":") + 1));
         sv.setWeight(tmp[1]);
         sv.setStatus(Integer.valueOf(Integer.parseInt(tmp[2])));
         sud.saveSV2(sv);
       }
       return true;
     } catch (Exception e) {
       e.printStackTrace();
     }return false;
   }
 
   public static String getManagerHost(HttpServletRequest request, int id, int status)
   {
     try
     {
       if (id == 1) {
         return getManagerHost(request, status);
       }
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       List li = sud.findSVByTypes2(4, status);
       if (li.size() != 0) {
         CocServer2 sv = (CocServer2)li.get(0);
         return sv.getIp() + ":" + sv.getPort();
       }
       return "";
     } catch (Exception e) {
       e.printStackTrace();
     }return "";
   }
 
   public static boolean setManagerHosts(HttpServletRequest request, int id, String serverStr)
   {
     try
     {
       if (id == 1) {
         return setManagerHosts(request, serverStr);
       }
 
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       List li = sud.findSVByTypes2(4, 1);
       for (int i = 0; i < li.size(); i++) {
         CocServer2 sv = (CocServer2)li.get(i);
         sud.delSV2(sv);
       }
       li = sud.findSVByTypes2(4, 0);
       for (int i = 0; i < li.size(); i++) {
         CocServer2 sv = (CocServer2)li.get(i);
         sud.delSV2(sv);
       }
       String[] str = serverStr.split(",");
       for (int i = 0; i < str.length; i++)
       {
         String[] tmp = str[i].split("\\|");
         CocServer2 sv = new CocServer2();
         sv.setTypes(Integer.valueOf(4));
         sv.setIp(str[i].substring(0, tmp[0].indexOf(":")));
         sv.setPort(str[i].substring(tmp[0].indexOf(":") + 1));
         sv.setWeight(tmp[1]);
         sv.setStatus(Integer.valueOf(Integer.parseInt(tmp[2])));
         sud.saveSV2(sv);
       }
       return true;
     } catch (Exception e) {
       e.printStackTrace();
     }return false;
   }
 
   public static String getPiratesHosts(HttpServletRequest request, int id, int status)
   {
     try
     {
       if (id == 1) {
         return getPiratesHosts(request, status);
       }
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       List li = sud.findSVByTypes2(2, status);
       String str = "";
       for (int i = 0; i < li.size(); i++) {
         CocServer2 sv = (CocServer2)li.get(i);
         if (str.equals(""))
           str = sv.getIp() + ":" + sv.getPort() + "|" + 
             sv.getWeight();
         else {
           str = str + "," + sv.getIp() + ":" + sv.getPort() + "|" + 
             sv.getWeight();
         }
       }
       return str;
     } catch (Exception e) {
       e.printStackTrace();
     }return "";
   }
 
   public static boolean setPiratesHosts(HttpServletRequest request, int id, String serverStr)
   {
     try
     {
       if (id == 1) {
         return setPiratesHosts(request, serverStr);
       }
 
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       List li = sud.findSVByTypes2(2, 1);
       for (int i = 0; i < li.size(); i++) {
         CocServer2 sv = (CocServer2)li.get(i);
         sud.delSV2(sv);
       }
       li = sud.findSVByTypes2(2, 0);
       for (int i = 0; i < li.size(); i++) {
         CocServer2 sv = (CocServer2)li.get(i);
         sud.delSV2(sv);
       }
       String[] str = serverStr.split(",");
       for (int i = 0; i < str.length; i++)
       {
         String[] tmp = str[i].split("\\|");
         CocServer2 sv = new CocServer2();
         sv.setTypes(Integer.valueOf(2));
         sv.setIp(str[i].substring(0, tmp[0].indexOf(":")));
         sv.setPort(str[i].substring(tmp[0].indexOf(":") + 1));
         sv.setWeight(tmp[1]);
         sv.setStatus(Integer.valueOf(Integer.parseInt(tmp[2])));
         sud.saveSV2(sv);
       }
       return true;
     } catch (Exception e) {
       e.printStackTrace();
     }return false;
   }
 
   public static String getBattleHosts(HttpServletRequest request, int status)
   {
     try
     {
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       List li = sud.findSVByTypes(3, status);
       String str = "";
       for (int i = 0; i < li.size(); i++) {
         CocServer sv = (CocServer)li.get(i);
         if (str.equals(""))
           str = sv.getIp() + ":" + sv.getPort() + "|" + 
             sv.getWeight();
         else {
           str = str + "," + sv.getIp() + ":" + sv.getPort() + "|" + 
             sv.getWeight();
         }
       }
       return str;
     } catch (Exception e) {
       e.printStackTrace();
     }return "";
   }
 
   public static boolean setBattleHosts(HttpServletRequest request, String serverStr)
   {
     try
     {
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       List li = sud.findSVByTypes(3, 1);
       for (int i = 0; i < li.size(); i++) {
         CocServer sv = (CocServer)li.get(i);
         sud.delSV(sv);
       }
       li = sud.findSVByTypes(3, 0);
       for (int i = 0; i < li.size(); i++) {
         CocServer sv = (CocServer)li.get(i);
         sud.delSV(sv);
       }
       String[] str = serverStr.split(",");
       for (int i = 0; i < str.length; i++)
       {
         String[] tmp = str[i].split("\\|");
         CocServer sv = new CocServer();
         sv.setTypes(Integer.valueOf(3));
         sv.setIp(str[i].substring(0, tmp[0].indexOf(":")));
         sv.setPort(str[i].substring(tmp[0].indexOf(":") + 1));
         sv.setWeight(tmp[1]);
         sv.setStatus(Integer.valueOf(Integer.parseInt(tmp[2])));
         sud.saveSV(sv);
       }
       return true;
     } catch (Exception e) {
       e.printStackTrace();
     }return false;
   }
 
   public static String getNginxHost(HttpServletRequest request, int status)
   {
     try
     {
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       List li = sud.findSVByTypes(1, status);
       if (li.size() != 0) {
         CocServer sv = (CocServer)li.get(0);
         return sv.getIp() + ":" + sv.getPort();
       }
       return "";
     } catch (Exception e) {
       e.printStackTrace();
     }return "";
   }
 
   public static boolean setNginxHosts(HttpServletRequest request, String serverStr)
   {
     try
     {
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       List li = sud.findSVByTypes(1, 1);
       for (int i = 0; i < li.size(); i++) {
         CocServer sv = (CocServer)li.get(i);
         sud.delSV(sv);
       }
       li = sud.findSVByTypes(1, 0);
       for (int i = 0; i < li.size(); i++) {
         CocServer sv = (CocServer)li.get(i);
         sud.delSV(sv);
       }
       String[] str = serverStr.split(",");
       for (int i = 0; i < str.length; i++)
       {
         String[] tmp = str[i].split("\\|");
         CocServer sv = new CocServer();
         sv.setTypes(Integer.valueOf(1));
         sv.setIp(str[i].substring(0, tmp[0].indexOf(":")));
         sv.setPort(str[i].substring(tmp[0].indexOf(":") + 1));
         sv.setWeight(tmp[1]);
         sv.setStatus(Integer.valueOf(Integer.parseInt(tmp[2])));
         sud.saveSV(sv);
       }
       return true;
     } catch (Exception e) {
       e.printStackTrace();
     }return false;
   }
 
   public static String getManagerHost(HttpServletRequest request, int status)
   {
     try
     {
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       List li = sud.findSVByTypes(4, status);
       if (li.size() != 0) {
         CocServer sv = (CocServer)li.get(0);
         return sv.getIp() + ":" + sv.getPort();
       }
       return "";
     } catch (Exception e) {
       e.printStackTrace();
     }return "";
   }
 
   public static boolean setManagerHosts(HttpServletRequest request, String serverStr)
   {
     try
     {
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       List li = sud.findSVByTypes(4, 1);
       for (int i = 0; i < li.size(); i++) {
         CocServer sv = (CocServer)li.get(i);
         sud.delSV(sv);
       }
       li = sud.findSVByTypes(4, 0);
       for (int i = 0; i < li.size(); i++) {
         CocServer sv = (CocServer)li.get(i);
         sud.delSV(sv);
       }
       String[] str = serverStr.split(",");
       for (int i = 0; i < str.length; i++)
       {
         String[] tmp = str[i].split("\\|");
         CocServer sv = new CocServer();
         sv.setTypes(Integer.valueOf(4));
         sv.setIp(str[i].substring(0, tmp[0].indexOf(":")));
         sv.setPort(str[i].substring(tmp[0].indexOf(":") + 1));
         sv.setWeight(tmp[1]);
         sv.setStatus(Integer.valueOf(Integer.parseInt(tmp[2])));
         sud.saveSV(sv);
       }
       return true;
     } catch (Exception e) {
       e.printStackTrace();
     }return false;
   }
 
   public static String getPiratesHosts(HttpServletRequest request, int status)
   {
     try
     {
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       List li = sud.findSVByTypes(2, status);
       String str = "";
       for (int i = 0; i < li.size(); i++) {
         CocServer sv = (CocServer)li.get(i);
         if (str.equals(""))
           str = sv.getIp() + ":" + sv.getPort() + "|" + 
             sv.getWeight();
         else {
           str = str + "," + sv.getIp() + ":" + sv.getPort() + "|" + 
             sv.getWeight();
         }
       }
       return str;
     } catch (Exception e) {
       e.printStackTrace();
     }return "";
   }
 
   public static boolean setPiratesHosts(HttpServletRequest request, String serverStr)
   {
     try
     {
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       List li = sud.findSVByTypes(2, 1);
       for (int i = 0; i < li.size(); i++) {
         CocServer sv = (CocServer)li.get(i);
         sud.delSV(sv);
       }
       li = sud.findSVByTypes(2, 0);
       for (int i = 0; i < li.size(); i++) {
         CocServer sv = (CocServer)li.get(i);
         sud.delSV(sv);
       }
       String[] str = serverStr.split(",");
       for (int i = 0; i < str.length; i++)
       {
         String[] tmp = str[i].split("\\|");
         CocServer sv = new CocServer();
         sv.setTypes(Integer.valueOf(2));
         sv.setIp(str[i].substring(0, tmp[0].indexOf(":")));
         sv.setPort(str[i].substring(tmp[0].indexOf(":") + 1));
         sv.setWeight(tmp[1]);
         sv.setStatus(Integer.valueOf(Integer.parseInt(tmp[2])));
         sud.saveSV(sv);
       }
       return true;
     } catch (Exception e) {
       e.printStackTrace();
     }return false;
   }
 
   public static String getFileDir(String filename, HttpServletRequest request)
   {
     try
     {
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       FileVersion fv = sud.findFVByFileName(filename);
       return fv.getFiledir();
     } catch (Exception e) {
       e.printStackTrace();
     }return "";
   }
 
   public static int getCurVer(String filename, HttpServletRequest request)
   {
     try
     {
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       FileVersion fv = sud.findFVByFileName(filename);
       return fv.getCurversion().intValue();
     } catch (Exception e) {
       e.printStackTrace();
     }return 0;
   }
 
   public static int getNextVer(String filename, HttpServletRequest request)
   {
     try
     {
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       FileVersion fv = sud.findFVByFileName(filename);
       return fv.getNextversion().intValue();
     } catch (Exception e) {
       e.printStackTrace();
     }return 0;
   }
 
   public static boolean setNextVer(String filename, int nextversion, HttpServletRequest request)
   {
     try
     {
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       FileVersion fv = sud.findFVByFileName(filename);
       fv.setNextversion(Integer.valueOf(nextversion));
       sud.saveFV(fv);
       return true;
     } catch (Exception e) {
       e.printStackTrace();
     }return false;
   }
 
   public static boolean clearNewFiles(HttpServletRequest request)
   {
     try
     {
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       List list = sud.findFVByTypes(1);
       for (int i = 0; i < list.size(); i++) {
         FileVersion fv = (FileVersion)list.get(i);
         fv.setNextversion(Integer.valueOf(0));
         sud.saveFV(fv);
       }
       list = sud.findFVByTypes(2);
       for (int i = 0; i < list.size(); i++) {
         FileVersion fv = (FileVersion)list.get(i);
         fv.setNextversion(Integer.valueOf(0));
         sud.saveFV(fv);
       }
       return true;
     } catch (Exception e) {
       e.printStackTrace();
     }return false;
   }
 
   public static boolean activeNewFiles(HttpServletRequest request)
   {
     try
     {
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       List list = sud.findFVByTypes(1);
       for (int i = 0; i < list.size(); i++) {
         FileVersion fv = (FileVersion)list.get(i);
 
         if (fv.getNextversion().intValue() > fv.getCurversion()
           .intValue()) {
           fv.setCurversion(fv.getNextversion());
           sud.saveFV(fv);
         }
       }
       list = sud.findFVByTypes(2);
       for (int i = 0; i < list.size(); i++) {
         FileVersion fv = (FileVersion)list.get(i);
 
         if (fv.getNextversion().intValue() > fv.getCurversion()
           .intValue()) {
           fv.setCurversion(fv.getNextversion());
           sud.saveFV(fv);
         }
       }
       return true;
     } catch (Exception e) {
       e.printStackTrace();
     }return false;
   }
 
   public static boolean run_linux_sh(String cmds)
   {
     Runtime rn = Runtime.getRuntime();
     Process p = null;
     try {
       p = rn.exec(cmds);
     } catch (Exception e) {
       System.out.println("Error win exec!");
       return false;
     }
     return true;
   }
 
   public static boolean run_pirates_temps_clear() {
     Runtime rn = Runtime.getRuntime();
     Process p = null;
     try {
       String cmds = "/usr/tomcat/apache-tomcat-6.0.36/linux_sh/pirates_temps_clear.sh";
       p = rn.exec(cmds);
     } catch (Exception e) {
       System.out.println("Error win exec!");
       return false;
     }
     return true;
   }
 
   public static boolean run_pirates_stop() {
     Runtime rn = Runtime.getRuntime();
     Process p = null;
     try {
       String cmds = "/usr/tomcat/apache-tomcat-6.0.36/linux_sh/pirates_stop.sh";
       p = rn.exec(cmds);
     } catch (Exception e) {
       System.out.println("Error win exec!");
       return false;
     }
     return true;
   }
 
   public static boolean run_pirates_update_cdn() {
     Runtime rn = Runtime.getRuntime();
     Process p = null;
     try {
       String cmds = "/usr/tomcat/apache-tomcat-6.0.36/linux_sh/pirates_update_cdn.sh";
       p = rn.exec(cmds);
     } catch (Exception e) {
       System.out.println("Error win exec!");
       return false;
     }
     return true;
   }
 
   public static boolean run_pirates_play() {
     Runtime rn = Runtime.getRuntime();
     Process p = null;
     try {
       String cmds = "/usr/tomcat/apache-tomcat-6.0.36/linux_sh/pirates_play.sh";
       p = rn.exec(cmds);
     } catch (Exception e) {
       System.out.println("Error win exec!");
       return false;
     }
     return true;
   }
 
   public static String listNewFiles(HttpServletRequest request) {
     try {
       ApplicationContext ctx = 
         WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession()
         .getServletContext());
       EloUserDAO sud = (EloUserDAO)ctx.getBean("eloUserDAO");
       List list = sud.findFVByTypes(1);
       StringBuffer sbf = new StringBuffer("[");
       int count = 0;
       for (int i = 0; i < list.size(); i++) {
         FileVersion fv = (FileVersion)list.get(i);
         if (fv.getNextversion().intValue() > 0) {
           if (count == 0)
             sbf.append("\"" + fv.getFilename() + "|" + 
               fv.getNextversion() + "\"");
           else {
             sbf.append(",\"" + fv.getFilename() + "|" + 
               fv.getNextversion() + "\"");
           }
           count++;
         }
       }
 
       list = sud.findFVByTypes(2);
       for (int i = 0; i < list.size(); i++) {
         FileVersion fv = (FileVersion)list.get(i);
         if (fv.getNextversion().intValue() > 0) {
           if (count == 0)
             sbf.append("\"" + fv.getFilename() + "|" + 
               fv.getNextversion() + "\"");
           else {
             sbf.append(",\"" + fv.getFilename() + "|" + 
               fv.getNextversion() + "\"");
           }
           count++;
         }
       }
       sbf.append("]");
 
       return sbf.toString();
     } catch (Exception e) {
       e.printStackTrace();
     }return "{}";
   }
 
   public static String getClassesPath(HttpServletRequest request)
   {
     try {
       String rootpath = request.getRealPath("/");
       if (rootpath != null)
         rootpath = rootpath.replaceAll("\\\\", "/");
       else {
         rootpath = "/";
       }
       if (!rootpath.endsWith("/")) {
         rootpath = rootpath + "/";
       }
 
       return rootpath + "WEB-INF//";
     } catch (Exception e) {
       e.printStackTrace();
     }return "";
   }
 
   public static String getCurrentTime()
   {
     String str = "";
     Date date = new Date();
     str = new SimpleDateFormat("yyyy-MM-dd").format(date).toString();
     return str;
   }
 
   public static String getCurrentTime(int day)
   {
     String str = "";
     Calendar calendar = Calendar.getInstance();
     calendar.setTime(new Date());
     calendar.set(5, calendar.get(5) - 
       day);
     str = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime())
       .toString();
     return str;
   }
 
   public static void check(int src)
   {
   }
 
   public static void main(String[] arg)
   {
    
   }
 
   public static String getBASE64Decode(String str) {
     byte[] bt = (byte[])null;
     try {
       BASE64Decoder decoder = new BASE64Decoder();
       bt = decoder.decodeBuffer(str);
     } catch (IOException e) {
       e.printStackTrace();
     }
     return new String(bt);
   }
 
   public static String doGetMethod(String url) {
     String str = "";
     try {
       HttpClient httpClient = new HttpClient();
       GetMethod getMethod = new GetMethod(url);
       int statusCode = httpClient.executeMethod(getMethod);
       str = getMethod.getResponseBodyAsString();
     } catch (Exception e) {
       e.printStackTrace();
     }
     return str;
   }
 
   public static String doPostMethod(String url, String postdata) {
     String str = "";
     try {
       HttpClient httpClient = new HttpClient();
       PostMethod postMethod = new PostMethod(url);
       postMethod.addRequestHeader("Content-Type", 
         "application/x-www-form-urlencoded; charset=UTF-8");
       postMethod.setRequestBody(postdata);
       int statusCode = httpClient.executeMethod(postMethod);
       str = postMethod.getResponseBodyAsString();
     } catch (Exception e) {
       e.printStackTrace();
     }
     return str;
   }
 
   public static String getMD5(String plainText)
   {
     String str = "";
     try {
       MessageDigest md = MessageDigest.getInstance("MD5");
       md.update(plainText.getBytes());
       byte[] b = md.digest();
 
       StringBuffer buf = new StringBuffer("");
       for (int offset = 0; offset < b.length; offset++) {
         int i = b[offset];
         if (i < 0)
           i += 256;
         if (i < 16)
           buf.append("0");
         buf.append(Integer.toHexString(i));
       }
       str = buf.toString();
     }
     catch (Exception e) {
       e.printStackTrace();
     }
 
     return str;
   }
 
   public static String getMD5_old(String plainText) {
     String str = "";
     try {
       MessageDigest md = MessageDigest.getInstance("MD5");
       md.update(plainText.getBytes());
       byte[] b = md.digest();
 
       StringBuffer buf = new StringBuffer("");
       for (int offset = 0; offset < b.length; offset++) {
         int i = b[offset];
         if (i < 0)
           i += 256;
         if (i < 16)
           buf.append("0");
         buf.append(Integer.toHexString(i));
       }
       str = buf.toString();
     }
     catch (Exception e) {
       e.printStackTrace();
     }
     return str;
   }
 
   public static String sortPostData(String data) {
     String[] _array = data.split("&");
     Arrays.sort(_array);
     String _data = "";
     for (String _param : _array)
       _data = _data + "&" + _param;
     return _data.substring(1);
   }
 
   public static String doHttpClientGet(String url) {
     String str = "";
     try {
       HttpClient httpClient = new HttpClient();
       GetMethod getMethod = new GetMethod(url);
       int statusCode = httpClient.executeMethod(getMethod);
       str = getMethod.getResponseBodyAsString();
     } catch (Exception e) {
       e.printStackTrace();
     }
     return str;
   }
 }

/* Location:           C:\Work\WorkSpace\classes\
 * Qualified Name:     com.coc.util.PubFun
 * JD-Core Version:    0.6.2
 */